package net.arvin.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

public class NetConnectionUtil {
	public static boolean isConnect(final Context context) {
		try {
			final ConnectivityManager connectivity = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			if (connectivity != null) {
				final NetworkInfo info = connectivity.getActiveNetworkInfo();
				if (info != null && info.isConnected()) {
					if (info.getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
		} catch (final Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public static boolean isConnectWithTip(final Context context,
			final String tip) {
		final boolean isConnect = isConnect(context);
		if (!isConnect) {
			Toast.makeText(context, tip, Toast.LENGTH_SHORT).show();
		}
		return isConnect;
	}
	
	public static boolean isConnectWithTip(final Context context,
			final int tip) {
		final boolean isConnect = isConnect(context);
		if (!isConnect) {
			Toast.makeText(context, tip, Toast.LENGTH_SHORT).show();
		}
		return isConnect;
	}
}
